package com.ruoyi.web.controller.app;

import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MyCost;
import com.ruoyi.system.service.IMyCostService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 项目欠费统计Controller
 * 
 * @author ruoyi
 * @date 2023-12-15
 */
@RestController
@RequestMapping("/system/cost")
public class MyCostController extends BaseController
{
    @Autowired
    private IMyCostService myCostService;

    /**
     * 查询项目欠费统计列表
     */
    @PreAuthorize("@ss.hasPermi('system:cost:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyCost myCost)
    {
        startPage();
        List<MyCost> list = myCostService.selectMyCostList(myCost);
        return getDataTable(list);
    }

    /**
     * 导出项目欠费统计列表
     */
    @PreAuthorize("@ss.hasPermi('system:cost:export')")
    @Log(title = "项目欠费统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MyCost myCost)
    {
        List<MyCost> list = myCostService.selectMyCostList(myCost);
        ExcelUtil<MyCost> util = new ExcelUtil<MyCost>(MyCost.class);
        util.exportExcel(response, list, "项目欠费统计数据");
    }

    /**
     * 获取项目欠费统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cost:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(myCostService.selectMyCostById(id));
    }

    /**
     * 新增项目欠费统计
     */
    @PreAuthorize("@ss.hasPermi('system:cost:add')")
    @Log(title = "项目欠费统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyCost myCost)
    {
        myCost.setId(UUID.randomUUID().toString());
        return toAjax(myCostService.insertMyCost(myCost));
    }
    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:cost:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<MyCost> util = new ExcelUtil<MyCost>(MyCost.class);
        List<MyCost> myCostList = util.importExcel(file.getInputStream());
        String operName = getUsername();
      String message = myCostService.importCost(myCostList, operName);
        return success(message);
    }
    /**
     * 修改项目欠费统计
     */
    @PreAuthorize("@ss.hasPermi('system:cost:edit')")
    @Log(title = "项目欠费统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyCost myCost)
    {
        return toAjax(myCostService.updateMyCost(myCost));
    }

    /**
     * 删除项目欠费统计
     */
    @PreAuthorize("@ss.hasPermi('system:cost:remove')")
    @Log(title = "项目欠费统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(myCostService.deleteMyCostByIds(ids));
    }
}
